package gui;
import java.awt.CardLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JPanel;

import Projektarbete.ContactTabListFiller;
import Projektarbete.Group;
import Projektarbete.User;


public class CreateGroupFrame extends javax.swing.JFrame {
	
	CardLayout layout;
	JPanel backGroundPanel;
	CreateGroupPanel1 panel1;
	CreateGroupPanel2 panel2;
	String[] infoArray;
	User user;
	
	public CreateGroupFrame(MainFrame mf) {
		user = mf.getUser();
		initComponents(mf);    	
    }
	
	public void changeCard(){
		infoArray = panel1.getInfo();
		layout.show(backGroundPanel, "PANEL2");
	}
	
    private void initComponents(MainFrame mf) {
    	infoArray = new String[2];
    	layout = new CardLayout();
    	backGroundPanel = new JPanel(layout);
    	ActionListener nextButtonActionListener = new ActionListener(){
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 changeCard();
             }
         };
         
         ActionListener finishButtonActionListener = new ActionListener(){
             public void actionPerformed(java.awt.event.ActionEvent evt) {
            	 ArrayList<User> memberArrayList = panel2.getMemerArrayList();
            	 System.out.println(memberArrayList.toString());
            	 Group group = new Group(user,infoArray[0],infoArray[1],memberArrayList);
            	 ContactTabListFiller filler = new ContactTabListFiller();
            	 filler.sendNewGroup(group);
            	 disposeFrame();
             }
         };
         
         
     	panel2 = new CreateGroupPanel2(finishButtonActionListener,mf.getUser());
     	panel1 = new CreateGroupPanel1(nextButtonActionListener);
     	backGroundPanel.add(panel1,"PANEL1");
     	backGroundPanel.add(panel2,"PANEL2");
         
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        backGroundPanel.setPreferredSize(new java.awt.Dimension(548, 415));
        setPreferredSize(new java.awt.Dimension(568, 430));
        backGroundPanel.setLayout(layout);
        this.setResizable(false);
        this.add(backGroundPanel);
        this.setVisible(true);
        pack();
    }
    
    public void disposeFrame(){
    	this.dispose();
    }
    
}
